<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>个人界面</title>
    <style>
        :root {
            --primary-color: #165DFF;
            --secondary-color: #4080FF;
            --accent-color: #FF7D00;
            --text-color: #333333;
            --light-text: #666666;
            --bg-color: #F5F7FA;
            --card-bg: #FFFFFF;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        body {
            background-color: var(--bg-color);
            background-image: 
                radial-gradient(circle at 25% 25%, rgba(22, 93, 255, 0.03) 0%, transparent 50%),
                radial-gradient(circle at 75% 75%, rgba(22, 93, 255, 0.03) 0%, transparent 50%);
            background-attachment: fixed;
            min-height: 100vh;
            color: var(--text-color);
        }

        .header {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            padding: 20px 40px;
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            z-index: 10;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            color: var(--primary-color);
            display: flex;
            align-items: center;
        }

        .logo i {
            margin-right: 10px;
            color: var(--accent-color);
        }

        /* 新增退出按钮样式 */
        .logout-button {
            background-color: #FF0000;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }

        .logout-button:hover {
            background-color: #CC0000;
        }

        /* AI 客服按钮样式 */
        .ai-button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            margin-right: 10px;
            display: flex;
            align-items: center;
        }

        .ai-button i {
            margin-right: 5px;
        }

        .ai-button:hover {
            background-color: var(--secondary-color);
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 120px 40px 40px;
            display: flex;
            flex-wrap: wrap;
            gap: 40px;
        }

        /* 优化后的个人信息卡片样式 */
        .profile-card {
            background: var(--card-bg);
            border-radius: 20px;
            box-shadow: 0 8px 30px rgba(22, 93, 255, 0.15);
            padding: 40px;
            width: 380px;
            transition: transform 0.3s ease;
            border: 1px solid rgba(22, 93, 255, 0.1);
        }

        .profile-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 12px 40px rgba(22, 93, 255, 0.2);
        }

        .avatar-container {
            text-align: center;
            margin-bottom: 30px;
        }

        .avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            border: 3px solid var(--primary-color);
            transition: transform 0.3s ease;
            cursor: pointer;
        }

        .profile-card:hover .avatar {
            transform: scale(1.05);
        }

        .profile-name {
            font-size: 24px;
            font-weight: 700;
            margin-bottom: 5px;
            color: var(--primary-color);
            text-align: center;
        }

        .profile-info {
            margin-top: 30px;
        }

        .profile-item {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
            padding: 12px 15px;
            border-radius: 10px;
            background-color: rgba(22, 93, 255, 0.05);
            transition: background-color 0.3s ease;
        }

        .profile-item:hover {
            background-color: rgba(22, 93, 255, 0.1);
        }

        .profile-item i {
            width: 30px;
            color: var(--primary-color);
            font-size: 18px;
        }

        .profile-value {
            font-size: 16px;
            margin-left: 15px;
        }

        /* 新增按钮样式 */
        .create-card-button {
            display: block;
            width: 100%;
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 12px;
            border-radius: 10px;
            cursor: pointer;
            text-align: center;
            text-decoration: none;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        .create-card-button:hover {
            background-color: var(--secondary-color);
        }

        .function-section {
            flex: 1;
            min-width: 300px;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 30px;
        }

        .function-card {
            background: var(--card-bg);
            border-radius: 16px;
            box-shadow: var(--shadow);
            padding: 30px;
            text-align: center;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            cursor: pointer;
        }

        .function-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: var(--primary-color);
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.3s ease;
        }

        .function-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 24px rgba(22, 93, 255, 0.12);
        }

        .function-card:hover::before {
            transform: scaleX(1);
        }

        .function-icon {
            width: 60px;
            height: 60px;
            background: rgba(22, 93, 255, 0.1);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 auto 20px;
            color: var(--primary-color);
            font-size: 24px;
        }

        .function-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .function-desc {
            font-size: 14px;
            color: var(--light-text);
            line-height: 1.6;
        }

        .footer {
            text-align: center;
            padding: 20px;
            color: var(--light-text);
            font-size: 14px;
            margin-top: 60px;
        }

        /* AI 客服浮窗样式 */
        .ai-chat-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 380px;
            max-height: 600px;
            background: var(--card-bg);
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            display: flex;
            flex-direction: column;
            z-index: 20;
            transition: transform 0.3s ease, opacity 0.3s ease;
            transform: translateY(100px);
            opacity: 0;
            visibility: hidden;
        }

        .ai-chat-container.active {
            transform: translateY(0);
            opacity: 1;
            visibility: visible;
        }

        .ai-chat-header {
            padding: 15px 20px;
            background: var(--primary-color);
            color: white;
            border-radius: 16px 16px 0 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            cursor: move;
        }

        .ai-chat-title {
            font-size: 18px;
            font-weight: 600;
            display: flex;
            align-items: center;
        }

        .ai-chat-title i {
            margin-right: 10px;
        }

        .ai-chat-close {
            cursor: pointer;
            font-size: 20px;
            transition: transform 0.2s ease;
        }

        .ai-chat-close:hover {
            transform: rotate(90deg);
        }

        .ai-chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }

        .ai-message, .user-message {
            max-width: 80%;
            padding: 12px 16px;
            border-radius: 12px;
            margin-bottom: 10px;
            position: relative;
            animation: fadeIn 0.3s ease forwards;
        }

        .ai-message {
            background: rgba(22, 93, 255, 0.1);
            color: var(--text-color);
            align-self: flex-start;
            border-radius: 0 12px 12px 12px;
        }

        .user-message {
            background: var(--primary-color);
            color: white;
            align-self: flex-end;
            border-radius: 12px 0 12px 12px;
        }

        .ai-message::before, .user-message::before {
            content: '';
            position: absolute;
            top: 0;
            width: 0;
            height: 0;
            border: 8px solid transparent;
        }

        .ai-message::before {
            left: -16px;
            border-right-color: rgba(22, 93, 255, 0.1);
            border-top-color: rgba(22, 93, 255, 0.1);
        }

        .user-message::before {
            right: -16px;
            border-left-color: var(--primary-color);
            border-top-color: var(--primary-color);
        }

        .ai-chat-input {
            padding: 15px 20px;
            border-top: 1px solid rgba(0, 0, 0, 0.05);
            display: flex;
            gap: 10px;
        }

        .ai-chat-input input {
            flex: 1;
            padding: 10px 15px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 20px;
            outline: none;
            font-size: 14px;
        }

        .ai-chat-input button {
            background: var(--primary-color);
            color: white;
            border: none;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background-color 0.2s ease;
        }

        .ai-chat-input button:hover {
            background: var(--secondary-color);
        }

        .ai-loading {
            display: inline-block;
            width: 12px;
            height: 12px;
            border: 2px solid rgba(22, 93, 255, 0.3);
            border-radius: 50%;
            border-top-color: var(--primary-color);
            animation: spin 1s linear infinite;
            margin-left: 10px;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
    <!-- 顶部导航 -->
    <div class="header">
        <div class="logo">
            <i class="fa fa-bank"></i>
            安心银行
        </div>
        <!-- AI 客服按钮 -->
        <button class="ai-button" id="aiChatButton">
            <i class="fa fa-comments"></i>
            AI 客服
        </button>
        <!-- 新增退出按钮 -->
        <a href="/" class="logout-button">退出登录</a>
    </div>

    <!-- 主要内容 -->
    <div class="container">
        <!-- 优化后的个人信息区 -->
        <div class="profile-card">
            <div class="avatar-container">
                <img src="https://picsum.photos/seed/user{{ user.id }}/120/120" alt="用户头像" class="avatar" id="userAvatar">
            </div>
            <div class="profile-name">{{ user.name }}</div>
            <div class="profile-info">
                <div class="profile-item">
                    <i class="fa fa-id-card"></i>
                    <div class="profile-value">身份证号：{{ user.pid[-4:] }}</div>
                </div>
                <div class="profile-item">
                    <i class="fa fa-money"></i>
                    <div class="profile-value">总存款：<strong>{{ user.balance }}</strong></div>
                </div>
                <a href="createcard" class="create-card-button">快捷开卡</a>
            </div>
        </div>

        <!-- 功能区 -->
        <div class="function-section">
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-credit-card"></i>
                </div>
                <a href="account" class="function-title">账户查询</a>
                <p class="function-desc">查询账户余额、明细及状态信息</p>
            </div>
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-exchange"></i>
                </div>
                <a href="trade" class="function-title">快捷转账</a>
                <p class="function-desc">快速便捷地向本行账户进行转账汇款</p>
            </div>
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-money"></i>
                </div>
                <a href="savemoney" class="function-title">充值/提现</a>
                <p class="function-desc">为账户进行余额充值，或余额提现</p>
            </div>
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-list-alt"></i>
                </div>
                <a href="flow" class="function-title">流水查询</a>
                <p class="function-desc">查看账户历史交易记录和资金流水</p>
            </div>
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-pencil"></i>
                </div>
                <a href="changeinfo" class="function-title">信息修改</a>
                <p class="function-desc">修改账户密码、联系方式等</p>
            </div>
            <div class="function-card">
                <div class="function-icon">
                    <i class="fa fa-shield"></i>
                </div>
                <a href="loss" class="function-title">挂失中心</a>
                <p class="function-desc">银行卡挂失、解挂及相关服务</p>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <div class="footer">
        © 2025 安心银行 
    </div>

    <!-- AI 客服浮窗 -->
    <div class="ai-chat-container" id="aiChatContainer">
        <div class="ai-chat-header" id="aiChatHeader">
            <div class="ai-chat-title">
                <i class="fa fa-robot"></i>
                智能客服
            </div>
            <div class="ai-chat-close" id="aiChatClose">
                <i class="fa fa-times"></i>
            </div>
        </div>
        <div class="ai-chat-messages" id="aiChatMessages">
            <!-- 欢迎消息 -->
            <div class="ai-message">
                <p>您好！我是安心银行智能客服，有什么可以帮助您的吗？</p>
            </div>
        </div>
        <div class="ai-chat-input">
            <input type="text" id="aiChatInput" placeholder="输入问题..." />
            <button id="aiChatSend">
                <i class="fa fa-paper-plane"></i>
            </button>
        </div>
    </div>

    <script>
        // 初始化变量
        const aiChatButton = document.getElementById('aiChatButton');
        const aiChatContainer = document.getElementById('aiChatContainer');
        const aiChatClose = document.getElementById('aiChatClose');
        const aiChatHeader = document.getElementById('aiChatHeader');
        const aiChatMessages = document.getElementById('aiChatMessages');
        const aiChatInput = document.getElementById('aiChatInput');
        const aiChatSend = document.getElementById('aiChatSend');
        
        // DeepSeek API 配置
        const API_URL = 'https://api.deepseek.com/v1/chat/completions';  // 修正为 chat/completions 接口
        const API_KEY = 'sk-27ff4664fab1499eb498fd95259b41b9';  // 替换为你的有效 API Key

        // 控制浮窗显示/隐藏
        aiChatButton.addEventListener('click', () => {
            aiChatContainer.classList.toggle('active');
            if (aiChatContainer.classList.contains('active')) {
                aiChatInput.focus();
            }
        });

        aiChatClose.addEventListener('click', () => {
            aiChatContainer.classList.remove('active');
        });

        // 实现拖拽功能
        let isDragging = false;
        let offsetX, offsetY;

        aiChatHeader.addEventListener('mousedown', (e) => {
            isDragging = true;
            offsetX = e.clientX - aiChatContainer.getBoundingClientRect().left;
            offsetY = e.clientY - aiChatContainer.getBoundingClientRect().top;
            aiChatContainer.style.transition = 'none';
        });

        document.addEventListener('mousemove', (e) => {
            if (!isDragging) return;
            
            const x = e.clientX - offsetX;
            const y = e.clientY - offsetY;
            
            // 限制浮窗在可视区域内
            const maxX = window.innerWidth - aiChatContainer.offsetWidth;
            const maxY = window.innerHeight - aiChatContainer.offsetHeight;
            
            aiChatContainer.style.left = Math.max(0, Math.min(x, maxX)) + 'px';
            aiChatContainer.style.top = Math.max(0, Math.min(y, maxY)) + 'px';
        });

        document.addEventListener('mouseup', () => {
            if (isDragging) {
                isDragging = false;
                aiChatContainer.style.transition = 'transform 0.3s ease, opacity 0.3s ease';
            }
        });

        function sendMessageToAI(message) {
            // 添加用户消息到界面
            addMessage('user', message);
            
            // 显示加载状态
            const loadingMessage = addMessage('assistant', '<div class="ai-loading"></div>');

            // 构建符合 DeepSeek 规范的请求体
            const requestBody = {
                model: "deepseek-chat",
                messages: [
                    ...getChatHistory(),
                    { role: "user", content: message }
                ],
                temperature: 0.7
            };

            // 调用 API
            fetch(API_URL, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': `Bearer ${API_KEY}`
                },
                body: JSON.stringify(requestBody)
            })
            .then(response => response.json())
            .then(data => {
                loadingMessage.remove();
                const aiResponse = data.choices[0].message.content;
                addMessage('assistant', aiResponse); // 注意角色改为 assistant！
            })
            .catch(error => {
                loadingMessage.remove();
                addMessage('assistant', `客服出错: ${error.message}`);
            });
        }

        // 添加消息到对话窗口
        function addMessage(type, content) {
            const messageDiv = document.createElement('div');
            messageDiv.className = type === 'user' ? 'user-message' : 'ai-message';
            messageDiv.innerHTML = `<p>${content}</p>`;
            aiChatMessages.appendChild(messageDiv);
            
            // 滚动到底部
            scrollToBottom();
            
            return messageDiv;
        }

        // 滚动到消息底部
        function scrollToBottom() {
            aiChatMessages.scrollTop = aiChatMessages.scrollHeight;
        }

        // 获取聊天历史记录
        function getChatHistory() {
            const messages = [];
            aiChatMessages.querySelectorAll('.user-message, .ai-message').forEach(msg => {
                const role = msg.classList.contains('user-message') ? 'user' : 'assistant';
                const content = msg.querySelector('p').textContent;
                messages.push({ role, content });
            });
            return messages;
        }

        // 发送消息事件
        function handleSendMessage() {
            const message = aiChatInput.value.trim();
            if (message) {
                sendMessageToAI(message);
                aiChatInput.value = '';
            }
        }

        aiChatSend.addEventListener('click', handleSendMessage);
        
        aiChatInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                handleSendMessage();
            }
        });

        // 头像点击效果
        document.getElementById('userAvatar').addEventListener('click', function() {
            const randomSeed = Math.floor(Math.random() * 1000);
            this.src = `https://picsum.photos/seed/${randomSeed}/120/120`;
        });
    </script>
</body>
</html>